<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *评价
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
			array('op'=>'list','title'=>'评价列表'),
			//array('op'=>'edit','title'=>'添加评价'),
	);

//评价
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_weishop_goods_comments',$params,array($pindex,$psize),$total,$fields);
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/member')->member_show($item['mid']);
			$item['goods']=$this->pdo_get('goods',array('id'=>$item['goodsid']),array('title','image'));
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','del_one'=>true,'delall'=>true,'list'=>array(
		//	array('name'=>'paixu','title'=>'顺序','type'=>'string'),
			array('name'=>'goods.title','title'=>'商品名称','type'=>'string'),
			array('name'=>'goods.image','title'=>'商品图片','type'=>'image'),
			array('name'=>'member','title'=>'评价者','type'=>'member'),
			array('name'=>'content','title'=>'评价内容','type'=>'string'),
			array('name'=>'createtime','title'=>'评价时间','type'=>'time'),
			array('name'=>'show','title'=>'状态','type'=>'switch','set'=>'set'),
	
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'评价者昵称','type'=>'string'),
			array('name'=>'show','width'=>15,'title'=>'状态','type'=>'select','options'=>'status2'),
		)
	);
	$return['status2']=array(array('id'=>0,'title'=>'隐藏'),array('id'=>1,'title'=>'显示'));
	$return['status']=array('0'=>'隐藏','1'=>'显示');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_weishop_goods_comments',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回评论列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'评价信息',
				'list'=>array(
					array('type'=>'choose','action'=>'jy_weishop/goods.get_goods/','name'=>'goodsid','title'=>'商品ID'),
					array('type'=>'images','title'=>'评价图片','name'=>'images','help'=>''),
					array('type'=>'text','title'=>'评价内容','name'=>'content','help'=>''),
					array('type'=>'radio','title'=>'星星','name'=>'star','options'=>'stars','help'=>''),
					array('type'=>'switch','title'=>'状态','name'=>'show','help'=>''),
				)
			),
		)
	);
	$return['stars']=array('0'=>'0星','1'=>'1星','2'=>'2星','3'=>'3星','4'=>'4星','5'=>'5星');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
	//	'paixu'=>intval($postdata['paixu']),
		'goodsid'=>intval($postdata['goodsid']),
		'show'=>intval($postdata['show']),
		'star'=>intval($postdata['star']),
		'images'=>ijson_encode($postdata['images']),
		'content'=>trim($postdata['content']),
		
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_weishop_goods_comments',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_weishop_goods_comments',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_goods_comments',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的公告！','error');
	}
	$post=get_postdata();
	if(isset($post['show'])){
		pdo_update('jy_weishop_goods_comments',array('show'=>intval($post['show'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
